home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Demos / Bowers Development / AppMaker 2.1.sit / AppMaker 2.1 / Examples / PowerPlant / List Test / CListTestDoc.cp / CListTestDoc.cp
Encoding:
Text File  |  1996-06-25  |  5.8 KB  |  290 lines  |  [TEXT/CWIE]

  1. // CListTestDoc.cp -- Document methods
  2. // Created 25/6/96 07:42 by AppMaker
  3.  
  4. #include "CListTestDoc.h"
  5. #include "CListTestData.h"
  6.  
  7. #include "CMain.h"
  8. #include "CmdCodes.h"
  9. #include "CAboutDialog.h"
  10.  
  11. #include <LFile.h>
  12. #include <LPlaceHolder.h>
  13. #include <LPrintout.h>
  14. #include <LWindow.h>
  15. #include <UWindows.h>
  16. #include <String_Utils.h>
  17.  
  18. const ResIDT    prto_PrintView        = 201;
  19. const ResIDT    STRx_Untitled        = 128;
  20.  
  21. // ---------------------------------------------------------------------------
  22. //        • CListTestDoc
  23. // ---------------------------------------------------------------------------
  24.  
  25. CListTestDoc::CListTestDoc(
  26.     LCommander    *inSuper)
  27.         : LSingleDoc(inSuper)
  28.     {
  29.         mData = new CListTestData();
  30.     }
  31.  
  32. // ---------------------------------------------------------------------------
  33. //        • ~CListTestDoc
  34. // ---------------------------------------------------------------------------
  35. //    Destructor
  36. //
  37.  
  38. CListTestDoc::~CListTestDoc()
  39. {
  40.     delete mData;
  41. }
  42.  
  43. //----------
  44. void
  45. CListTestDoc::newFile()
  46. {
  47. mData->newData();
  48.  
  49. MakeWindows();
  50.  
  51. NameNewDoc();        // Set name of untitled window
  52. }
  53.  
  54. //----------
  55. void
  56. CListTestDoc::openFile(
  57.     FSSpec        *inFileSpec)
  58. {
  59.     mData->openData (inFileSpec);
  60.  
  61.     MakeWindows();
  62.  
  63.     if (mWindow != nil) {
  64.         mWindow->SetDescriptor (inFileSpec->name);
  65.     }
  66.     mIsSpecified = true;
  67. }
  68.  
  69.     // ---------------------------------------------------------------------------
  70.     //        • MakeWindows
  71.     // ---------------------------------------------------------------------------
  72.  
  73.     void
  74.     CListTestDoc::MakeWindows()
  75.     {
  76.         mMain = CMain::CreateMain(this, mData);
  77.  
  78.         mWindow = mMain;
  79.     }
  80.  
  81. // ---------------------------------------------------------------------------
  82. //        • NameNewDoc
  83. // ---------------------------------------------------------------------------
  84. //    Name a new, untitled document window
  85. //
  86. //    Untitled windows start with "untitled", then "untitled 1",
  87. //    "untitled 2", etc. Old numbers are reused, so there won't be
  88. //    gaps in the numbering.
  89. //
  90. //    This routine uses a STR# resource to store the "untitled" string,
  91. //    which can be localized to different languages. The first string
  92. //    is "untitled" and the second is "untitled " (trailing space),
  93. //    which is used when appending a number to the name.
  94.  
  95. void
  96. CListTestDoc::NameNewDoc()
  97. {
  98.     // Start with the default name("untitled")
  99.     Str255    name;
  100.     ::GetIndString(name, STRx_Untitled, 1);
  101.  
  102.     long    num = 0;
  103.     while (UWindows::FindNamedWindow(name) != nil) {
  104.  
  105.             // An existing window has the current name
  106.             // Increment counter and try again
  107.  
  108.         ::GetIndString(name, STRx_Untitled, 2);
  109.         num++;
  110.         Str15    numStr;
  111.         ::NumToString(num, numStr);
  112.         ConcatPStr(name, numStr);
  113.     }
  114.  
  115.     mWindow->SetDescriptor(name);        // Finally, set window title
  116. }
  117.  
  118. // ---------------------------------------------------------------------------
  119. //        • IsModified
  120. // ---------------------------------------------------------------------------
  121. //    Return whether the Document has changed since the last save
  122.  
  123. Boolean
  124. CListTestDoc::IsModified()
  125. {
  126.     mIsModified = mData->IsDirty();
  127.  
  128.     return mIsModified;
  129. }
  130.  
  131. // ---------------------------------------------------------------------------
  132. //        • DoAESave
  133. // ---------------------------------------------------------------------------
  134. //    Save Document in the specified file with the specified file type
  135. //
  136. //    If file type is fileType_Default, use the normal file type for
  137. //    this document
  138.  
  139. void
  140. CListTestDoc::DoAESave(
  141.     FSSpec    &inFileSpec,
  142.     OSType    inFileType)
  143. {
  144.     mData->DoSaveAs(&inFileSpec);                // Write out data
  145.                                         // Change window name
  146.     mWindow->SetDescriptor(inFileSpec.name);
  147. }
  148.  
  149. //----------
  150. void
  151. CListTestDoc::DoSave()
  152. {
  153.     mData->DoSave();
  154. }
  155.  
  156. //----------
  157. void
  158. CListTestDoc::DoRevert()
  159. {
  160.     mData->DoRevert();
  161. }
  162.  
  163. // ---------------------------------------------------------------------------
  164. //        • DoPrint
  165. // ---------------------------------------------------------------------------
  166. //    Print the contents of the Document
  167.  
  168. void
  169. CListTestDoc::DoPrint()
  170. {
  171.     LPrintout        *thePrintout = LPrintout::CreatePrintout(prto_PrintView);
  172.     LPlaceHolder    *textPlace = (LPlaceHolder *)
  173.                                     thePrintout->FindPaneByID('TBox');
  174. //!    textPlace->InstallOccupant(mTextView, atNone);
  175.  
  176.  
  177.     thePrintout->DoPrintJob();
  178.     delete thePrintout;
  179. }
  180.  
  181. //----------
  182. Boolean
  183. CListTestDoc::DoBeep ()
  184. {
  185. Boolean    cmdHandled = true;
  186. SysBeep(10);
  187. return cmdHandled;
  188. }
  189.  
  190. //----------
  191. Boolean
  192. CListTestDoc::DoTwoBeeps ()
  193. {
  194. Boolean    cmdHandled = true;
  195. SysBeep(10);
  196. SysBeep(10);
  197. return cmdHandled;
  198. }
  199.  
  200. //----------
  201. Boolean
  202. CListTestDoc::DoAboutListTest ()
  203. {
  204. Boolean    cmdHandled = true;
  205. CAboutDialog*    dialog = CAboutDialog::CreateAboutDialog(this);
  206. return cmdHandled;
  207. }
  208.  
  209. //----------
  210. void
  211. CListTestDoc::ObeyAboutDialog    (void*    ioParam)
  212. {
  213. CAboutDialog*    dialog = (CAboutDialog *)ioParam;
  214.  
  215. // do something with dialog values
  216.  
  217. delete dialog;
  218. }
  219.  
  220. //----------
  221. Boolean
  222. CListTestDoc::ObeyCommand(
  223.     CommandT    inCommand,
  224.     void        *ioParam)
  225. {
  226.     Boolean        cmdHandled = true;
  227.  
  228.     switch (inCommand) {
  229.  
  230.     // +++ Add cases here for the commands you handle
  231.     //        Remember to add same cases to FindCommandStatus below
  232.     //        to enable/disable the menu items for the commands
  233.  
  234.  
  235.     case cmdBeep:
  236.         cmdHandled = DoBeep ();
  237.         break;
  238.  
  239.     case cmdTwoBeeps:
  240.         cmdHandled = DoTwoBeeps ();
  241.         break;
  242.  
  243.     case cmdAboutListTest:
  244.         cmdHandled = DoAboutListTest ();
  245.         break;
  246.  
  247.     case cmdOKdialog_AboutDialog:    
  248.         ObeyAboutDialog    (ioParam);
  249.         break;
  250.  
  251.     default:
  252.             cmdHandled = LSingleDoc::ObeyCommand(inCommand, ioParam);
  253.         break;
  254.     }
  255.  
  256.     return cmdHandled;
  257. }
  258.  
  259. //----------
  260. void
  261. CListTestDoc::FindCommandStatus(
  262.     CommandT    inCommand,
  263.     Boolean        &outEnabled,
  264.     Boolean        &outUsesMark,
  265.     Char16        &outMark,
  266.     Str255        outName)
  267. {
  268.     outUsesMark = false;
  269.  
  270.     switch (inCommand) {
  271.  
  272.     // +++ Add cases here for the commands you handle
  273.  
  274.     case cmdBeep:
  275.         outEnabled = true;
  276.         break;
  277.     case cmdTwoBeeps:
  278.         outEnabled = true;
  279.         break;
  280.     case cmdAboutListTest:
  281.         outEnabled = true;
  282.         break;
  283.  
  284.     default:
  285.             LSingleDoc::FindCommandStatus(inCommand, outEnabled,
  286.                                             outUsesMark, outMark, outName);
  287.         break;
  288.     }
  289. }
  290.